/**
* @Title: warning_ctrl.js
* @Description: TODO
* Copyright: Copyright (c) 2014 
 * Company:中国平安
*
* @Project HIMS-FWA
* @date 2014年10月27日 下午4:43:38
* @version V1.0
*/
;
(function(){
	'use strict';
	
	var app = angular.module('fwa.mainApp');
	app.controller('CaseCheckProcessCtrl', ['$scope','$http','$modal','BaseURL','Modal','CaseCommonService','CaseAuditFindDispathService','WarningAddService','FwaTabsetService','CommunityService','$stateParams','$state','WarningScreenService','AuditDictServices',
	                                function($scope,$http,$modal,baseUrl,Modal,CaseCommonService,CaseAuditFindDispathService,WarningAddService,fwaTabsetService,CommunityService,$stateParams,$state,WarningScreenService,AuditDictServices){
		
		$scope.auditDictServices = AuditDictServices;
        AuditDictServices.initCodeListDatas();
        
	   /****************** 一下处理日期的函数,目的是获取t+5日期*******************/
		Date.prototype.format = function(format)
		{
			var o = {
			"M+" : this.getMonth()+1, //month
			"d+" : this.getDate(),    //day
			"h+" : this.getHours(),   //hour
		 	"m+" : this.getMinutes(), //minute
			"s+" : this.getSeconds(), //second
		 	"q+" : Math.floor((this.getMonth()+3)/3),  //quarter
		 	"S" : this.getMilliseconds() //millisecond
			}

			if(/(y+)/.test(format)) 
			{
				format=format.replace(RegExp.$1,(this.getFullYear()+"").substr(4 - RegExp.$1.length));
			}
			
		 	for(var k in o)
			{
				if(new RegExp("("+ k +")").test(format))
				{
		 			format = format.replace(RegExp.$1,RegExp.$1.length==1 ? o[k] : ("00"+ o[k]).substr((""+ o[k]).length));
				}
			}
			return format;
		}

		var currentDate= new Date();
		currentDate.setDate(currentDate.getDate()+5);
		var currentDeadLine = currentDate.format('yyyy-MM-dd');
		
	/**********************************************************/
		
		$scope.problemProcessOpinion={}; // 处理意见
		$scope.problemAuditOpinion={}; // 审核意见
		$scope.surveyResult={}; // 调查详情
		$scope.surveyReview={}; // 调查复核
		$scope.surveyAudit={}; // 调查审核
		$scope.auditProjectList=[]; // 稽核项目列表
		$scope.caseCheckResult={}; // 稽核结果
		$scope.caseReviewResult={}; // 稽核复核结果
		$scope.caseApproveResult={}; //稽核结论审批
		$scope.reportBean={}; //稽核报告
		$scope.caseDetail={}; //稽核告知函
		
		
		$scope.dispatchButton=true;
		$scope.confirmButton=true;
		$scope.showDeadLine=false;
		
		$scope.showReport=false; //展现稽核报告和稽核告知函
		
		$scope.auditObj={
				affirmDeadline:currentDeadLine
		}; //审核对象
		
		$scope.tempStaffList=new Array(); //临时保存医务人员信息
		$scope.tempInsuranceList=new Array();//临时保存参保人信息
		
		var sourceTab = [{label:'稽核结果',id:3,url:'views/hcpms/audit/caseCheck/caseCheckAuditResult_view.html'},
		                 {label:'稽核结果',id:3,url:'views/hcpms/audit/caseCheck/caseCheckRollBack_view.html'}];
		
        $scope.problemtab=[ {label:'事件处理',id:0,url:'views/hcpms/audit/caseCheck/caseCheckProblemDeal.html'},
            {label:'调查结果',id:1,url:'views/hcpms/audit/caseCheck/caseCheckSurveyResult.html'},
            {label:'稽核项目',id:2,url:'views/hcpms/audit/caseCheck/caseCheckAuditPorject_view.html'}];

        $scope.tabClicks = function(tab) {
            $scope.selectedTabs = tab;
            $scope.tabIndex = tab.id;
            setTimeout(function(){
				$(window).trigger('resize');
            },0);
        }
        
        
        $scope.columns = [
                          {label:'项目名称',map:'projectName',width:'20%'},
                          {label:'结算方式',map:'treatTypeName',width:'20%'},
                          {label:'不合理费用',map:'deductionAmmountStr',width:'20%'},
                          {label:'备注',map:'remark',width:'40%'}
                         ];
       $scope.tableData = [];
       
       $scope.selectList=[{code:'1',label:'同意'},{code:'0',label:'重新稽核'}];
       
          //初始化请求参数
	    function params(){
			var caseCode = "";
			if($stateParams.caseCode && !angular.isUndefined($stateParams.caseCode) ){
				caseCode = $stateParams.caseCode;
				$scope.caseCode=caseCode;
				$scope.problemCode=$stateParams.problemCode;
				
			}
			var params = {
					caseCode:caseCode,
					problemCode:$scope.problemCode
			}
			return params;
		}
       
	    $scope.enableEdit = true;
       
       /**
        * 初始化案件对象
        */
       $scope.object={};
       function initCaseInfo(){
    	   var parameter=params();
    	   CaseCommonService.loadCaseData(parameter).success(function(response){   	 
    		   var _obj = response.result.case1;
    		   $scope.object= _obj;
		   		if(_obj.caseState==6){
		   			$scope.problemtab.push(sourceTab[1]);
		   			$scope.enableEdit = false;
		   			$scope.medicalShow={add:false,deduction:false,del:false};
		   			$scope.staffShow={add:false,deduction:false,del:false};
		   			$scope.insuranceShow={add:false,deduction:false,del:false};
		    	 }else{
		    		 $scope.problemtab.push(sourceTab[0]);
		    		 $scope.medicalShow={add:false,deduction:true,del:false};
		    		 $scope.staffShow={add:true,deduction:true,del:true};
		    		 $scope.insuranceShow={add:true,deduction:false,del:true};
		    	 }
    		   $scope.tabClicks($scope.problemtab[3]);
			});
    	   
       }
       
       /**
        * 初始化医疗机构,医务人员,参保人信息
        */
       $scope.medicalCode='';
       function initMedicalAndStaffAndInsurance(){
    	   var obj=params();
    	   var parameter={
    			   problemNo:obj.caseCode,
    			   taskType:'2'             //案件
    	   };
			CaseCommonService.loadMedicalInfoList(parameter).success(function(response){   	 
				$scope.medicalData2=response.medicalBean.medicalList;
                if($scope.medicalData2.length>0)
                {
                    if($scope.medicalData2[0].medicalCode)
                    {
                        $scope.medicalCode=$scope.medicalData2[0].medicalCode;
                    }
                }
				$scope.staffData2=response.staffBean.staffList;
				$scope.insuranceData2=response.insuranceBean.insuranceList;
				CaseCommonService.initStaffAndInsuranceTempList($scope);
				//更新当前页面数据
     		   WarningScreenService.findPointCutTempScose(
     				   WarningAddService.warningMarks,$stateParams.caseCode,'02',
     				   $scope.medicalData2[0],$scope.staffData2,$scope.insuranceData2);
			});
       }
       /**
        * 初始化各个tab 信息
        */
       function initTabInfo(){
    	 var parameteObject=params();
    	   $http({
				method : 'post',
				cache : false,
				url : baseUrl + 'caseCheckAudit/loadCaseInfo.do',
				params :parameteObject
			}).success(function(response, status, headers, config) {


				processResponseResult(response);

			});
    	   
       }
       
       /**
        * 处理初始化tab返回的信息
        */
       function processResponseResult(response){
    	 
    	   if(response.problemProcessOpinion){
    		   var opinion=response.problemProcessOpinion.opinion;
    		   $scope.problemProcessOpinion=response.problemProcessOpinion;
    		   if(opinion=='1'){
    			   $scope.problemProcessOpinion.opinionValue="需要调查";
    		   }else if(opinion=='0'){
    			   $scope.problemProcessOpinion.opinionValue="无需调查";
    		   }else if(opinion=='2'){
    			   $scope.problemProcessOpinion.opinionValue="转其他部门处理";
    		   }
    	   }
    	   
    	   if(response.problemAuditOpinion){
    		   $scope.problemAuditOpinion=response.problemAuditOpinion;
    		   var opinion=response.problemAuditOpinion.opinion;
    		   if(opinion=='1'){
    			   $scope.problemAuditOpinion.opinionValue="同意";
    		   }else if(opinion=='0'){
    			   $scope.problemAuditOpinion.opinionValue="不同意";
    		   }else if(opinion=='2'){
    			   $scope.problemProcessOpinion.opinionValue="转其他部门处理";
    		   }
    	   }
    	   if(response.surveyResult){
    	
    		   $scope.surveyResult=response.surveyResult;
    		   var opinion=response.surveyResult.opinion;
    		   if(opinion=='1'){
    			   $scope.surveyResult.opinionValue="需要稽核";
    		   }else if(opinion=='0'){
    			   $scope.surveyResult.opinionValue="无需稽核";
    		   }else if(opinion=='2'){
    			   $scope.problemProcessOpinion.opinionValue="转其他部门处理";
    		   }
    		   
    	   }
    	   
    	   if(response.surveyReview){
    	    	
    		   $scope.surveyReview=response.surveyReview;
    		   var opinion=response.surveyReview.opinion;
    		   if(opinion=='1'){
    			   $scope.surveyReview.opinionValue="同意";
    		   }else if(opinion=='0'){
    			   $scope.surveyReview.opinionValue="保留意见";
    			  
    		   }else if(opinion=='2'){
    			   $scope.problemProcessOpinion.opinionValue="转其他部门处理";
    		   }
    		   
    	   }
    	   
    	   if(response.surveyAudit){
   	    	
    		   $scope.surveyAudit=response.surveyAudit;
    		   var opinion=response.surveyAudit.opinion;
    		   if(opinion=='1'){
    			   $scope.surveyAudit.opinionValue="同意";
    		   }else if(opinion=='0'){
    			   $scope.surveyAudit.opinionValue="重新稽核";
    		   }else if(opinion=='2'){
    			   $scope.problemProcessOpinion.opinionValue="转其他部门处理";
    		   }
    		   
    	   }
    	   
    	   if(response.auditProjectList){
      	    	
    		   $scope.tableData=response.auditProjectList;
    		   
    	   }
    	   
    	   if(response.caseCheckResult){ //稽核结论
    		   $scope.caseCheckResult=response.caseCheckResult;
    		   var caseResult=response.caseCheckResult.caseResult;
    		   if(caseResult=='1'){
    			   $scope.caseCheckResult.caseResultValue='正常';
    			   $scope.showReport=false;
    		   }else if(caseResult=='0'){
    			   $scope.caseCheckResult.caseResultValue='异常';
    			   $scope.showReport=true;
    		   }
    		   
    		  
    		   
    	   }
    	   
    	   if(response.caseReviewResult){ //稽核复核
    		   $scope.caseReviewResult=response.caseReviewResult;
    		   var opinion=response.caseReviewResult.opinion;
    		   if(opinion=='0'){
    			   $scope.caseReviewResult.opinionValue="保留意见";
    			   $scope.selectList=[{code:'0',label:'重新稽核'}];
    		   }else if(opinion=='1'){
    			   $scope.caseReviewResult.opinionValue="同意";
    		   }
    		   
    	   }
    	   
    	   if(response.caseAuditResult){ //稽核审核意见
    		   $scope.auditObj.opinion=response.caseAuditResult.opinion;
    		   $scope.auditObj.opinionDesc=response.caseAuditResult.opinionDesc;
    	   }
    	   
    	   if(response.caseApproveResult){ //稽核结论审批意见
    		   $scope.caseApproveResult=response.caseApproveResult;
    		   var opinion=response.caseApproveResult.opinion;
    		   if(opinion=='0'){
    			   $scope.caseApproveResult.opinionValue="不同意";
    		   }else if(opinion=='1'){
    			   $scope.caseApproveResult.opinionValue="同意";
    		   }
    		 $scope.problemtab.push({label:'审批结果',id:4,url:'views/hcpms/audit/caseCheck/caseApproveReback.html'});
    	   }
    	   
    	   
    	   //初始化审核数据
    	   initTempInfo();
    	   
    	   
       }
       
       
       
       /**
        * 初始化所有的数据
        */
       function initAllData(){
    	   initTabInfo();
    	  initCaseInfo();
    	  initMedicalAndStaffAndInsurance();
    	 
       }
       
       initAllData();
       
       
       /**审核意见选择监听函数***/
		$scope.selectChangeFun=function(){
			
			if($scope.auditObj){
				var opinion=$scope.auditObj.opinion;
				if(opinion && opinion=='1'){ //同意
					$scope.confirmButton=true;
					$scope.dispatchButton=false;
					
				}else{
					$scope.confirmButton=false;
					$scope.dispatchButton=true;
					
				}
				//稽核结论异常且审核意见是同意,则截止日期展现否则不展现
				/**
				if($scope.caseCheckResult.caseResult=='0' && opinion=='1'){
					if(!$scope.auditObj.affirmDeadline){
						$scope.auditObj.affirmDeadline=currentDeadLine;  //审核对象
					}
					$scope.showDeadLine=true;
				}else{
					$scope.showDeadLine=false;
				}
				**/
				
				
			}
			
		}
       
		
	
		
		/**
		 * 分配事件
		 */
		$scope.onDispatchClick=function(){
            $scope.warnMarkTempDetails = WarningAddService.warningMarks;
			  if($scope.auditObj.opinion=='1'){
				  
				  if(!$scope.auditObj.opinionDesc){
	    		    	 Modal.alert('审核意见描述不能为空!');
	    	    		   return;
	    		    }
	    		   
	    	   }else if($scope.auditObj.opinion=='0'){
	    		   
	    		    if(!$scope.auditObj.opinionDesc){
	    		    	 Modal.alert('审核意见描述不能为空!');
	    	    		   return;
	    		    }
	    	   }else{
	    		   Modal.alert('审核意见不能为空!');
	    		   return;
	    	   }
		var scope = $scope.$new();
		var modalInstance = $modal.open({
		      templateUrl: baseUrl+'views/hcpms/audit/caseCheck/caseCheckDispatchSelectUserDialog_view.html',
		      backdrop:'static',
			  size:'sm',
			  scope:scope,
			  controller: 'caseCheckDispatchSelectUserModalCtrl'
		    });
			  
		}
		
       /**
        *确定事件
        */
		 $scope.loading = false;
       $scope.onConfirmClick=function(obj){
    	   if($scope.auditObj.opinion=='1'){
    		   
    		   if(!$scope.auditObj.opinionDesc){
  		    	 Modal.alert('审核意见描述不能为空!');
  	    		   return;
  		    }
    		   
    	   }else if($scope.auditObj.opinion=='0'){
    		   
    		    if(!$scope.auditObj.opinionDesc){
    		    	 Modal.alert('审核意见描述不能为空!');
    	    		   return;
    		    }
    		   
    	   }else{
    		   Modal.alert('审核意见不能为空!');
    		   return;
    	   }
    	   
    	   //稽核结论异常且审核意见同意则截止日期不能为空
          /* if($scope.auditObj.opinion=='1' && $scope.caseCheckResult.caseResult=='0'){
        	        if(!$scope.auditObj.affirmDeadline){
        	        	Modal.alert("截止日期不能为空!");
        	        	return;
        	        }
           }*/

    	   var paramter=params();
    	   paramter.auditOpinion=$scope.auditObj.opinion;
    	   paramter.auditOpinionDesc=$scope.auditObj.opinionDesc;
    	   paramter.auditFirstOpinion=$scope.caseCheckResult.caseResult;
    	   paramter.auditSecondOpinion=$scope.caseReviewResult.opinion;
    	   paramter.affirmDeadline=$scope.auditObj.affirmDeadline;
    	   paramter.reviewOpinionDesc=$scope.caseReviewResult.opinionDesc;
           paramter.warnMarkTempDetails=WarningAddService.warningMarks;
    	   if(obj){
    		   paramter.userAName=obj.userAName;
        	   paramter.userBName=obj.userBName;
    	   }
    	   $scope.loading = true;
    	   $scope.saveReallyStaffAndInsuarnceInfo();
           CaseAuditFindDispathService.processCaseCofirm(paramter).success(function(data){
               if(data.result){
            	   $scope.loading = false;
                   $scope.onBackClick();
               }
           });
       }
        /**
         * 医疗机构扣分事件
         */
        $scope.$on('fwaInvolve.medicalDeduction',function(e,v){
            $scope.marking (1,v, v.medicalCode, v.orgType);
        });
        /**
         * 医务人员扣分事件
         */
        $scope.$on('fwaInvolve.staffDeduction',function(e,v){
            $scope.marking(2,v,$scope.medicalCode,'');
        });
        //扣分 mark：1.机构扣分，2.医务人员扣分，3参保人员扣分,data:数据集合
        $scope.marking = function(mark,data,medicalCode,orgType){
            var medicalCodeTemp=null;
            if(medicalCode&&!angular.isUndefined(medicalCode)){
                medicalCodeTemp = medicalCode;
            }
            if(mark != 1 && medicalCodeTemp == null){
                Modal.alert("请先增加医疗机构信息！");
                return null;
            }else{
                medicalCode = medicalCodeTemp;
            }
            markData(mark,data,medicalCode,orgType);//扣分数据参数加载
            var modalInstance = $modal.open({
                templateUrl: baseUrl+'views/hcpms/warning/warnEdit/warningDeductionDialog_view.html',
                backdrop:'static',
                size:'sm',
                scope: $scope,
    //					  scope:scope,
                controller: 'WarningDeductionDialogCtrl'
            });
            //接收返回数据
            modalInstance.result.then(function(item) {
                if (!WarningAddService.warningMarks) {
                    WarningAddService.warningMarks = [];
                }
                WarningAddService.warningMarks = item;
                //更新当前页面数据
     		   	WarningScreenService.findPointCutTempScose(
     		   		item,$stateParams.caseCode,'02',
     		   	$scope.medicalData2[0],$scope.staffData2,$scope.insuranceData2);
            });
        }
        //扣分数据参数加载
        var markData = function(mark,data,medicalCode,orgType){
            WarningAddService.mark = mark;
            WarningAddService.warningMarkData = {
                orgType:orgType,//0.机构，1.药店
                medicalCode:medicalCode,//medicalCode:所属机构编号
                code:data.selfCode,//code:编号
                name:data.name,//name:名称
                caseType:'02',//案件类型caseType：01.预警,02.稽核
                caseNo: $stateParams.caseCode,//事件编号
                happenDate: $scope.object.auditDate,//稽核时间
                punishDateStart: $scope.object.periodBeginDate,// 稽核开始日期
                punishDateEnd: $scope.object.periodEndDate,// 稽核结束日期
                warningMarks:WarningAddService.warningMarks
            };
        }
        
        /**
         * 初始化稽核告知函的报告
         */
        function ininAuditNotifiaction(){
        	var parameter={
        			caseCode:$stateParams.caseCode
        	};
          CaseCommonService.loadAuditNotifionInfo(parameter).success(function(response){   
				$scope.reportBean=response.reportBean;
				$scope.caseDetail=response.tellReportBean;
				$scope.reportBean.auditRang={
		       			   start:$scope.reportBean.auditStart,
		       			   end:$scope.reportBean.auditEnd
		       	      };
			});
        }
        ininAuditNotifiaction();
        /**
         * 展现稽核报告对话框
         */
        $scope.showCaseAuditReportDialog=function(){
        	ininAuditNotifiaction();
        	var scope = $scope.$new();
	       	scope.caseDetail=$scope.reportBean;
        	scope.typeRead=false;
        	 CaseCommonService.showCaseAuditReportDialog(scope);
        }
        
        /**
         * 展现稽核告知函
         */
        $scope.showCaseAuditTellReportDialog=function(){
        	ininAuditNotifiaction();
        	var scope = $scope.$new();
        	scope.typeRead=false;
	       	scope.caseDetail=$scope.caseDetail;
        	CaseCommonService.showCaseAuditTellReportDialog(scope);//
        }

       var warningMarks = [];
       /**
        * 返回事件
        */
       $scope.onBackClick=function(){
    	   WarningAddService.warningMarks = WarningAddService.warningMarkTemps;//初始化扣分参数

           if($stateParams.urlFlag){
               var urlFlag =  $stateParams.urlFlag;
               fwaTabsetService.closeTab('caseCheck','workingArea.auditPost',{urlFlag:urlFlag});
           }else
           {
               $state.go('caseCheck.caseCheckList');
           }
       }
       
       
      
       /**
        * 调新增医务人员的回调函数
        *  parameter={
         * taskCode:'',
         * taskType:'',1事件,2案件
         * targetType:'',对象类型(1-医疗机构2-医生3-参保人)
         * targetCode:''
         * }
        */
       $scope.callStaffFun=function(array){
    	   CaseCommonService.addTempStaffList(array,$scope);
    	
       }
       
       /**
        * 医务人员删除
        */
       $scope.$on('fwaInvolve.staffDel',function(e,data){
    	   Modal.confirm('确认删除医务人员'+data.name+'吗？',function(){
				WarningScreenService.deleteMark(WarningAddService.warningMarks,2,data);//mark:1.机构，2.医务人员，3.参保人
				 CaseCommonService.deleteTempStaffList(data,$scope);
			});
    	   
    	  
         });
       
       /**
        * 调新增参保人员的回调函数
        */
       $scope.callInsuranceFun=function(array){
    	 CaseCommonService.addTempInsuranceListInfo(array,$scope);
       }
       
     
       
       
       /**
        * 点击医疗机构量事件
        * 
        */
       $scope.$on('fwaInvolve.medicalCountClick',function(){
    	   CaseCommonService.viewMedicalDetail($scope);
       });
       
       /**
        * 新增医护人员事件
        */
       $scope.$on('fwaInvolve.staffAdd',function(){
    	   CaseCommonService.addStaffFun($scope);
    	   
       });
       
       
       /**
        * 新增参保人员事件
        */
       $scope.$on('fwaInvolve.insuranceAdd',function(){
    	   CaseCommonService.addInsuranceFun($scope);
    	   
       });
       
       
       /**
        * 查看案件信息对象中案件来源对话框
        */
       $scope.$on('fwaAuditLeft.showModal',function(){
    	   $scope.caseObj=$scope.object;
    	   CaseCommonService.showCaseFromSourceDialog($scope);
       });
       
       
       /**
        * 暂存处理事件
        */
       $scope.loading = false;
       $scope.onTempClick=function(){
              if($scope.auditObj.opinion=='1'){
    		   
    	       }else if($scope.auditObj.opinion=='0'){
    		   
	    		    if(!$scope.auditObj.opinionDesc){
	    		    	 Modal.alert('审核意见描述不能为空!');
	    	    		   return;
	    		    }
	    		   
    	   }else{
    		   Modal.alert('审核意见不能为空!');
    		   return;
    	   }
           
              //稽核结论异常且审核意见同意则截止日期不能为空
          /* if($scope.auditObj.opinion=='1' && $scope.caseCheckResult.caseResult=='0'){
        	        if(!$scope.auditObj.affirmDeadline){
        	        	Modal.alert("截止日期不能为空!");
        	        	return;
        	        }
           }*/
              
           var parameter={
               problemNo:$stateParams.caseCode,
               type:'save',
               opinion:$scope.auditObj.opinion,
               opinionDesc:$scope.auditObj.opinionDesc,
               affirmDeadline:$scope.auditObj.affirmDeadline,
               reviewOpinionDesc:$scope.caseReviewResult.opinionDesc,
               warnMarkTempDetails:WarningAddService.warningMarks
           };
           $scope.loading = true;
           $scope.saveStaffAndInsuarnceInfo();
           CaseAuditFindDispathService.caseProcessOpinion(parameter).success(function(data){
               var flag=data.flag;
               if(flag){
            	   $scope.loading = false;
                   Modal.alert('暂存保存成功!');
                   WarningAddService.warningMarks = [];
                  	//更新当前页面数据
         		   WarningScreenService.findPointCutTempScose(
         				   WarningAddService.warningMarks,$stateParams.caseCode,'02',
         				   $scope.medicalData2[0],$scope.staffData2,$scope.insuranceData2);
               }
           });
         
       }
       
       
       /**
        * 初始化暂存信息
        */
       function initTempInfo(){
    	   var parameter={
    			   problemNo:$stateParams.caseCode,
					type:'load'
    	   };
    	   
    	   $http.post(baseUrl + 'caseCheckAudit/processTempSave.do',parameter).success(function(response){
    		   if(response.auditOpinion){
    			    $scope.auditObj=response.auditOpinion;
					$scope.auditObj.opinion=response.auditOpinion.opinion;
					$scope.auditObj.opinionDesc=response.auditOpinion.opinionDesc;
					$scope.selectChangeFun();
				 }else{
					 $scope.selectChangeFun(); 
				 }
    	   });
       }
       
       
       
       /**
        * 点击医务人员总数量事件
        */
       $scope.$on('fwaInvolve.staffCountClick',function(){
       	CaseCommonService.viewStaffList($scope);
       });
       
       /**
        * 点击参保人总数量事件
        */
       $scope.$on('fwaInvolve.insuranceCountClick',function(){
         	CaseCommonService.viewInsurList($scope);
       });
       
      
       
       /**
        * 参保人员删除
        */
       $scope.$on('fwaInvolve.insuranceDel',function(e,data){
    	   
    	   Modal.confirm('确认删除参保人员'+data.name+'吗？',function(){
				WarningScreenService.deleteMark(WarningAddService.warningMarks,3,data);//mark:1.机构，2.医务人员，3.参保人
				 CaseCommonService.deleteTempInsuranceInfoList(data,$scope);
			});
    	   
    	  
         });
     
       
       /**
        * 对医务人员和参保人员的暂存信息保存
        */
       $scope.saveStaffAndInsuarnceInfo=function(){
    	   $scope.saveType="temp";
    	   saveStaffListInfo();
    	   saveInsuranceInfo();
       }
       
       /**
        * 对医务人员和参保人员的真实数据信息保存
        */
       $scope.saveReallyStaffAndInsuarnceInfo=function(){
          $scope.saveType="save";
          saveStaffListInfo();
          saveInsuranceInfo();
       }

       
       
	   /**
	    * 暂存的时候对医务人员进行的保存
	    */
       function saveStaffListInfo(){
	   CaseCommonService.saveTempStaffListInfo($scope,'2','2',$stateParams.caseCode);
	   
       }
       
       /**
	    * 暂存的时候对参保人员进行的保存
	    */
       function saveInsuranceInfo(){
    	   CaseCommonService.saveTempInsuranceListInfo($scope,'2','3',$stateParams.caseCode);
       }
     
       /**
	    * 撤回
	    */  
       $scope.returnClick=function (){
    	  $scope.loading = !$scope.loading;
      	 var premer={
      			 code:$stateParams.caseCode,
      			 status:"6",
      			 type:"02"
      	 }
          CaseCommonService.caseRollBack(premer).success(
	           function(response, status, headers, config){
	        	   $scope.loading = !$scope.loading;
	        	   Modal.alert(response.result.message);
                   $scope.onBackClick();
	            });
      	 
       }
       
       
       
	
	}]);
})();